/*
 * semaphore.c
 *
 *  Created on: Mar 4, 2013
 *      Author: abrahamsantini
 */

#include "semaphore.h"

int semaphore_init(semaphore_t *sp,int s) {
	sp -> size = s;
	sp -> count = 0;
	int ret = sp -> count;
	return ret;
}


int semaphore_down(semaphore_t *sp) {
	int ret;
	if (sp -> count > 0) {
		sp -> count--;
		ret = sp -> count;
	} else {
		ret = -1;
	}
	return ret;
}
int semaphore_up(semaphore_t *sp) {
	int ret;
	if(sp -> count < (sp -> size)) {
		sp -> count++;
		ret = sp -> count;
	} else {
		ret = -1;
	}
	return ret;
}
int semaphore_getCount(semaphore_t *sp) {
	return sp -> count;
}

